<template>
    <div class="graph-main" v-if="graphList.length">
        <h3>知识图谱</h3>
        <div class="graph-right-button"><div><span>查看全部</span><i class="el-icon-right"></i></div></div>
        <div class="graph-middle">
            <div class="graph-item" v-for="(item,index) of graphList" :key="item.id" @click="jumpPath(item)">
                <div class="graph-img"><img :src="imageArr[index]"></div>
                <p class = "graph-title">{{item.graphName}}</p>
                <p>{{item.createTime}}</p>
            </div>
        </div>
    </div>
</template>
<script>
import http from "@/utils/http.js"
import grpahImg1 from '@/assets/img/graph1.png'
import grpahImg2 from '@/assets/img/graph2.png'
import grpahImg3 from '@/assets/img/graph3.png'
import grpahImg4 from '@/assets/img/graph4.png'

export default {
    data(){
        return {
            graphList:[],
            imageArr:[
                grpahImg1,
                grpahImg2, 
                grpahImg3, 
                grpahImg4
            ],
            baseUrl:"http://10.202.80.186:8882"
        }
    },
    created(){
        this.getGraphList()
    },
    methods:{
        async getGraphList(){
            const res=await http.getGraphList()
            if(res.data){
                let allList=res.data.data || []
                this.graphList = allList.slice(0, 4)
            }
            console.log(res.data.data)
        },
        jumpPath(item){
            //点击图谱的div跳转页面
            const proxy = encodeURIComponent(`${this.baseUrl}/#/sub-graph-detail`)
            const link = `/proxy?proxyUrl=${proxy}&id=${item.id}&graphName=${item.graphName}&layout=${item.layout}&isGraph=true`
            this.$router.push(link)
        }
    }
}
</script>
<style lang="scss" scoped>
.graph-main {
    width: 100%;
    height: 425px;
    padding-top: 30px;
    h3 {
        text-align: center;
        font-size: 25px;
        font-weight: bold;
    }
}

.graph-right-button {
    text-align: center;
    margin: 0 auto;
    width: 90px;
    height: 31px;
    background: #409EFF;
    border-radius: 25px;
    margin-top: 20px;
    div{
        padding-top: 5px ;
        span{
            color: #FFF;
            margin-right: 5px;
        }
        i {
            color: #FFF!important;
        }
    }
}

.graph-middle {
    display: flex;
    margin-top: 28px;
    justify-content: center;
    align-items: center;
    .graph-item {
      cursor: pointer;
      max-width: 320px;
      flex: 1;
      width: 20%;
      padding: 18px;
      font-size: 12px;
      margin: 0 20px;
      background: #FFFFFF;
      box-shadow: 2px 4px 16px 0px rgba(14, 16, 76, 0.08);
      border-radius: 4px;
      p {
        color: #303133;
        min-height: 18px;
        font-size: 16px;
        line-height: 18px;
      }
      .graph-img {
        width: 100%;
        height: 156px;
        border: 1px dashed #e7e7e7;
        overflow: hidden;
      }
      img {
        width: 100%;
        height: 100%;
        transition: 0.3s;
      }
      .graph-title {
        color: #303133;
        font-size: 18px;
        margin: 18px 0 10px;
        font-weight: 500;
        white-space:nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      &:hover {
        img {
          transform: scale(1.1);
        }
      }
    }
  }
</style>